<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>身份验证</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" th:href="@{../../lib/layui/css/layui.css}">
    <script charset="utf-8" th:src="@{../../lib/layui/layui.js}" type="text/javascript"></script>
    <!--    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>-->
    <script th:src="@{../../js/jquery-3.5.1.min.js}" type="text/javascript"></script>
    <style>
        .vintage {
            background: #EEE url() repeat;
            text-shadow: 5px -5px black, 4px -4px white;
            font-weight: bold;
            -webkit-text-fill-color: transparent;
            -webkit-background-clip: text
        }
    </style>
</head>
<body>
<div>
    <h1 th:class="vintage">如果你是管理员，请输入密钥</h1>
</div>
<hr class="hr15"/>
<hr/>
<form class="layui-form">
    <div class="layui-form-item">
        <label for="secretKey" class="layui-form-label">密钥</label>
        <div class="layui-input-inline">
            <input autocomplete="off" class="layui-input" id="secretKey" name="secretKey" lay-verify="L_secretKey"
                   placeholder="请输入管理员密钥" type="password" style="border: 1px solid #5538bb">
        </div>
    </div>
    <hr class="hr15"/>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="adminAuth" lay-submit="" type="submit">验证</button>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        $ = layui.jquery;

        var form = layui.form,
            layer = layui.layer;

        form.verify({
            L_secretKey: function (value) {
                if (value.length <= 0) {
                    return "请输入密钥后再进行验证"
                }
            }
        })

        // 监听提交
        form.on('submit(adminAuth)',
            function () {
                var secretKey = document.getElementById("secretKey").value;
                $.ajax({
                    url: '/sys/adminAuth',
                    data: {
                        secretKey: secretKey
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        if (data === 0) {
                            var index = parent.layer.getFrameIndex(window.name);
                            layer.msg("验证成功，正在进入用户列表页，请稍等...", {icon: 1, time: 1500, shade: 0.4}, function () {
                                var window = parent.document.getElementById("main");
                                window.src = "/sys/user_operation";
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg("验证失败，请重新输入", {icon: 2, time: 1500, shade: 0.4}, function () {
                                document.getElementById("secretKey").value = "";
                            })
                        }
                    }
                });
                return false;
            }
        );
    });
</script>
</body>